package com.mo.lib.http

import androidx.fragment.app.FragmentActivity
import com.drake.net.callback.DialogCallback
import com.drake.net.exception.NetUnknownHostException
import com.drake.net.exception.RequestParamsException
import com.mo.lib.ui.dialog.LoadingDialog
import com.mo.lib.utils.KLog
import com.mo.lib.utils.showToast
import okhttp3.Call
import java.io.IOException
import java.util.concurrent.CancellationException

/**
 * @ author：mo
 * @ data：2021/10/12:11:50
 * @ 功能：
 */
abstract class KCallBack<T> constructor(activity: FragmentActivity, cancelable: Boolean = true)
    : DialogCallback<T>(activity, LoadingDialog().dialog, cancelable) {
    override fun onError(call: Call, e: IOException) {
        super.onError(call, e)
        when (e) {
            is NetUnknownHostException -> {
                showToast("网络未连接")
            }
            is CancellationException -> {
                showToast("网络取消异常")
            }
            is RequestParamsException->{
                showToast("请求参数异常")
                KLog.i(e.message.toString())
            }
        }
    }
}
abstract class KCallBack2<T> ()
    : NetCallback2<T>() {
}

